package com.dgh.school.controller;

import com.dgh.school.bean.Clerk;
import com.dgh.school.common.R;
import com.dgh.school.service.ClerkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClerkController {

    @Autowired
    private ClerkService clerkService;

    @RequestMapping("/clerk/clerks")
    public R selectByPage(int pageNum, int pageSize){
        try {
            return clerkService.selectByPage(pageNum,pageSize);
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/clerk/delete")
    public R deleteById(int id){
        try {
            clerkService.deleteById(id);
            System.out.println(id);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/clerk/add")
    public R add(Clerk clerk){
        try {
            clerkService.insertData(clerk);
            System.out.println(clerk);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/clerk/modify")
    public R modify(Clerk clerk){
        try {
            clerkService.updateData(clerk);
            System.out.println(clerk);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }



}
